﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BarberShop.BLL;
using BarberShop.Model;

public partial class StoresManage : BasePage
{
    StoresInfoSearch _searchP = new StoresInfoSearch();
    protected StoresInfoSearch _search
    {
        get
        {
            _searchP.BrandId = int.Parse(drp_Brand_Id.SelectedValue == "" ? "-1" : drp_Brand_Id.SelectedValue);
            _searchP.CityId = int.Parse(drp_procive_Id.SelectedValue == "" ? "-1" : drp_procive_Id.SelectedValue);
            _searchP.ProvinceId = int.Parse(drp_city_Id.SelectedValue == "" ? "-1" : drp_city_Id.SelectedValue);
            _searchP.StoreName = txt_storesName.Text.Trim();
            return _searchP;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetStroeData();
            BandBrandinfo();
            BandProviceinfo();
            BandCityinfo();
        }
    }

    //getData
    protected void GetStroeData()
    {
        var data = StoresInfoBLL.GetStoresList(_search);
        this.Grid_Store.DataSource = data;
        this.Grid_Store.DataKeyNames = new string[] { "Id" };
        this.Grid_Store.DataBind();
    }
    #region 绑定品牌
    public void BandBrandinfo()
    {
        this.drp_Brand_Id.DataSource = BrandInfoBLL.GetAllBrandList();
        this.drp_Brand_Id.DataTextField = "BrandName";
        this.drp_Brand_Id.DataValueField = "ID";

        this.drp_Brand_Id.DataBind();
        this.drp_Brand_Id.Items.Insert(0, new ListItem { Value = "-1", Text = "" });
    }
    #endregion

    #region 绑定身份
    public void BandProviceinfo()
    {
        this.drp_procive_Id.DataSource = BarberCommonBLL.GetAllProvinceList();
        this.drp_procive_Id.DataTextField = "ProName";
        this.drp_procive_Id.DataValueField = "ProID";
        this.drp_procive_Id.DataBind();
        this.drp_procive_Id.Items.Insert(0, new ListItem { Value = "-1", Text = "" });
    }
    #endregion

    #region 绑定城市
    public void BandCityinfo()
    {
        if (this.drp_procive_Id.SelectedValue != "")
        {
            int proid = int.Parse(this.drp_procive_Id.SelectedValue);
            this.drp_city_Id.DataSource = BarberCommonBLL.GetCityListByPID(proid);
            this.drp_city_Id.DataTextField = "CityName";
            this.drp_city_Id.DataValueField = "CityID";
            this.drp_city_Id.DataBind();
            this.drp_city_Id.Items.Insert(0, new ListItem { Value = "-1", Text = "" });
        }
    }
    #endregion

    protected void drp_procive_Id_SelectedIndexChanged(object sender, EventArgs e)
    {
        BandCityinfo();
    }

    protected void btn_search_Click(object sender, EventArgs e)
    {
        GetStroeData();
    }

    protected void Grid_Store_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        Grid_Store.PageIndex = e.NewSelectedIndex;
    }
    protected void Grid_Store_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "CreateXML")
        {
            int ID = int.Parse(e.CommandArgument.ToString());
            StoresInfoBLL.CreateShopXML(ID);
            GetStroeData();
        } 
    }
}
